﻿namespace SERFLITEMAX20.WinUI.Controls
{
    using SERFLITEMAX20.Core;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class frmListValues : Form
    {
        private Button btnClear;
        private Button btnListValues;
        private ColumnHeader columnHeader1;
        private ColumnHeader columnHeader10;
        private ColumnHeader columnHeader11;
        private ColumnHeader columnHeader8;
        private ColumnHeader columnHeader9;
        private IContainer components = null;
        private Label label2;
        private Label label3;
        private ListView lstView;
        private int mBasePtr = 0;
        private TextBox mFrom;
        private ListViewSortManager mListViewSortManager = null;
        private Main mMain = null;
        private TextBox mTo;
        private TextBox textBox1;
        private TextBox txtEvery;

        public frmListValues()
        {
            this.InitializeComponent();
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            this.lstView.Items.Clear();
        }

        private void btnListValues_Click(object sender, EventArgs e)
        {
            this.lstView.Items.Clear();
            try
            {
                this.mListViewSortManager = new ListViewSortManager(this.lstView, new System.Type[] { typeof(ListViewTextSort), typeof(ListViewTextSort), typeof(ListViewTextSort), typeof(ListViewTextSort), typeof(ListViewTextSort) });
                int num = int.Parse(this.mFrom.Text);
                int num2 = int.Parse(this.mTo.Text);
                int num3 = int.Parse(this.txtEvery.Text);
                for (int i = num; i <= num2; i += num3)
                {
                    ListViewItem item = this.lstView.Items.Add(i.ToString());
                    string str = "";
                    string text = this.mMain.Memory.ReadInteger(this.mBasePtr + i).ToString();
                    item.SubItems.Add(text);
                    str = "INT:" + text;
                    text = this.mMain.Memory.ReadFloat(this.mBasePtr + i).ToString();
                    item.SubItems.Add(text);
                    str = str + "\tFLOAT:" + text;
                    text = this.mMain.Memory.ReadLong(this.mBasePtr + i).ToString();
                    item.SubItems.Add(text);
                    str = str + "\tLONG:" + text;
                    int address = this.mMain.Memory.ReadInteger(this.mBasePtr + i);
                    string str3 = "";
                    if (address != 0)
                    {
                        address = this.mMain.Memory.ReadInteger(address + 8);
                        if (address != 0)
                        {
                            str3 = this.mMain.Memory.ReadString(address, 0x40);
                        }
                    }
                    str = str + "\tSTRING:" + str3;
                    item.SubItems.Add(str3);
                    item.Tag = str;
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.lstView = new System.Windows.Forms.ListView();
            this.columnHeader8 = new System.Windows.Forms.ColumnHeader();
            this.columnHeader10 = new System.Windows.Forms.ColumnHeader();
            this.columnHeader11 = new System.Windows.Forms.ColumnHeader();
            this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
            this.columnHeader9 = new System.Windows.Forms.ColumnHeader();
            this.btnListValues = new System.Windows.Forms.Button();
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.mTo = new System.Windows.Forms.TextBox();
            this.mFrom = new System.Windows.Forms.TextBox();
            this.btnClear = new System.Windows.Forms.Button();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.txtEvery = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            // 
            // lstView
            // 
            this.lstView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.lstView.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.lstView.CheckBoxes = true;
            this.lstView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
            this.columnHeader8,
            this.columnHeader10,
            this.columnHeader11,
            this.columnHeader1,
            this.columnHeader9});
            this.lstView.FullRowSelect = true;
            this.lstView.GridLines = true;
            this.lstView.HideSelection = false;
            this.lstView.Location = new System.Drawing.Point(-1, 72);
            this.lstView.Name = "lstView";
            this.lstView.Size = new System.Drawing.Size(861, 282);
            this.lstView.TabIndex = 1;
            this.lstView.UseCompatibleStateImageBehavior = false;
            this.lstView.View = System.Windows.Forms.View.Details;
            this.lstView.DoubleClick += new System.EventHandler(this.lstView_DoubleClick);
            // 
            // columnHeader8
            // 
            this.columnHeader8.Text = "Row";
            this.columnHeader8.Width = 50;
            // 
            // columnHeader10
            // 
            this.columnHeader10.Text = "Int";
            this.columnHeader10.Width = 116;
            // 
            // columnHeader11
            // 
            this.columnHeader11.Text = "Float";
            this.columnHeader11.Width = 139;
            // 
            // columnHeader1
            // 
            this.columnHeader1.Text = "Long";
            // 
            // columnHeader9
            // 
            this.columnHeader9.Text = "String";
            this.columnHeader9.Width = 340;
            // 
            // btnListValues
            // 
            this.btnListValues.Location = new System.Drawing.Point(415, 7);
            this.btnListValues.Name = "btnListValues";
            this.btnListValues.Size = new System.Drawing.Size(94, 26);
            this.btnListValues.TabIndex = 2;
            this.btnListValues.Text = "List Values";
            this.btnListValues.UseVisualStyleBackColor = true;
            this.btnListValues.Click += new System.EventHandler(this.btnListValues_Click);
            // 
            // label2
            // 
            this.label2.Location = new System.Drawing.Point(211, 12);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(33, 20);
            this.label2.TabIndex = 6;
            this.label2.Text = "To";
            // 
            // label3
            // 
            this.label3.Location = new System.Drawing.Point(5, 12);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(37, 20);
            this.label3.TabIndex = 5;
            this.label3.Text = "From";
            // 
            // mTo
            // 
            this.mTo.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.mTo.Location = new System.Drawing.Point(250, 12);
            this.mTo.Name = "mTo";
            this.mTo.Size = new System.Drawing.Size(147, 20);
            this.mTo.TabIndex = 3;
            // 
            // mFrom
            // 
            this.mFrom.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.mFrom.Location = new System.Drawing.Point(48, 12);
            this.mFrom.Name = "mFrom";
            this.mFrom.Size = new System.Drawing.Size(163, 20);
            this.mFrom.TabIndex = 4;
            // 
            // btnClear
            // 
            this.btnClear.Location = new System.Drawing.Point(530, 7);
            this.btnClear.Name = "btnClear";
            this.btnClear.Size = new System.Drawing.Size(94, 26);
            this.btnClear.TabIndex = 2;
            this.btnClear.Text = "Clear";
            this.btnClear.UseVisualStyleBackColor = true;
            this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
            // 
            // textBox1
            // 
            this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.textBox1.Location = new System.Drawing.Point(647, 10);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(147, 20);
            this.textBox1.TabIndex = 7;
            this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
            // 
            // txtEvery
            // 
            this.txtEvery.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.txtEvery.Location = new System.Drawing.Point(250, 46);
            this.txtEvery.Name = "txtEvery";
            this.txtEvery.Size = new System.Drawing.Size(147, 20);
            this.txtEvery.TabIndex = 8;
            this.txtEvery.Text = "1";
            // 
            // frmListValues
            // 
            this.ClientSize = new System.Drawing.Size(861, 354);
            this.Controls.Add(this.txtEvery);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.mTo);
            this.Controls.Add(this.mFrom);
            this.Controls.Add(this.btnClear);
            this.Controls.Add(this.btnListValues);
            this.Controls.Add(this.lstView);
            this.Name = "frmListValues";
            this.ShowInTaskbar = false;
            this.Text = "List Values";
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        private void lstView_DoubleClick(object sender, EventArgs e)
        {
            if (this.lstView.SelectedItems.Count > 0)
            {
                string pType = new frmSelectType().View();
                if (pType != null)
                {
                    this.mMain.RaiseAddWatchEvent(this.mBasePtr, int.Parse(this.lstView.SelectedItems[0].SubItems[0].Text), pType);
                }
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            this.mTo.Text = (int.Parse(this.mFrom.Text) + int.Parse(this.textBox1.Text)).ToString();
        }

        public void View(Main pMain, BaseObject pObject)
        {
            this.mMain = pMain;
            if (pObject != null)
            {
                this.Text = pObject.BasePtr.ToString();
                this.mBasePtr = pObject.BasePtr;
            }
            base.Show();
        }
    }
}

